package dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.handlers.BeanHandler;

import bean.User;
import dao.UserDao;


public class UserDaoImpl extends BaseDao implements UserDao {
	public Integer deleteUserbyid(Integer id) {
		try {
			return query.update("delete from user where userid=?",id);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

	@Override
	public Integer selectUserbyid(Integer id) {
		try {
			Object query2=query.query("select * from user where userid=?",id,new BeanHandler<User>(User.class));
			return Integer.parseInt(query2.toString());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

	@Override
	public Integer updateUser(User info) {
		String sql="UPDATE user set username=?,userpwd=?,usertel=?,usertouxiangid=?,usersex=?,userjob=?,useraddress=?,userintroduction=?,userlevel=? where userid=?";
		try {
			return query.update(sql,info.getUsername(),info.getUserpwd(),info.getUsertel(),info.getUsersex(),info.getUsertouxiangid(),info.getUserjob(),info.getUseraddress(),info.getUserintroduction(),info.getUserlevel(),info.getUserid());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

	@Override
	public Integer addUser(User info) {
		String sql="insert into user(username,userpwd,usertel,usertouxiangid,usersex,userjob,useraddress,userintroduction,userlevel) VALUES(?,?,?,?,?,?,?,?,?)";
		try {
			return query.update(sql,info.getUsername(),info.getUserpwd(),info.getUsertel(),info.getUsersex(),info.getUsertouxiangid(),info.getUserjob(),info.getUseraddress(),info.getUserintroduction(),info.getUserlevel());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}

	
}
